package com.reggie.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.reggie.acl.dataobject.OrderDetail;
import com.reggie.acl.mapper.OrderDetailMapper;
import com.reggie.service.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单明细表 服务实现类
 * </p>
 *
 * @author yth
 * @since 2023-02-04
 */
@Service
public class OrderDetailServiceImpl implements OrderDetailService {

    @Autowired
    private OrderDetailMapper orderDetailMapper;

    @Override
    public void save(List<OrderDetail> orderDetails) {
        // TODO 待优化
        for (OrderDetail orderDetail : orderDetails) {
            orderDetailMapper.insert(orderDetail);
        }
    }

    @Override
    public List<OrderDetail> getByOrderId(long ordersId) {
        LambdaQueryWrapper<OrderDetail> wrapper = Wrappers.lambdaQuery(OrderDetail.class);
        wrapper.eq(OrderDetail::getOrderId, ordersId);
        return orderDetailMapper.selectList(wrapper);
    }

    @Override
    public List<OrderDetail> getByOrderIds(List<Long> ordersIds) {
        LambdaQueryWrapper<OrderDetail> wrapper = Wrappers.lambdaQuery(OrderDetail.class);
        wrapper.in(OrderDetail::getOrderId, ordersIds);
        return orderDetailMapper.selectList(wrapper);
    }

}
